package com.ssg1_8;

public class ArrayExe_4 {
    public static void main(String[] args) {
        //数组的反转
        int [] arr={1,343,6,7,58,35,5};
        System.out.println("反转前：");
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
        //法一
        System.out.println("反转后：");
      /*  for (int i = 0; i <arr.length/2 ; i++) {
            int temp=arr[i];
             arr[i]=arr[arr.length-1-i];
            arr[arr.length-1-i]=temp;
        }*/
        //法二：
        for (int i = 0,j=arr.length-1; i <j ; i++,j--) {
                int temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
        }

        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+"\t");
        }
    }
}
